import my_db_util as db
import time
import numpy as np
import datetime

count = 1
last_timestamp = 1


def get_id():
    global last_timestamp, count
    curr_timestamp = int(time.time() * 1000)
    if last_timestamp != curr_timestamp:
        last_timestamp = curr_timestamp
        return str(last_timestamp) + str("{:04d}".format(count))
    else:
        count = count + 1
        return str(last_timestamp) + str("{:04d}".format(count))


filename = 'D:\\vrdata\\下载记录.csv'
conn = db.get_conn()
cursor = conn.cursor()
# delimiter参数的作用是指定分隔符,dtype参数的作用是指定数据类型
datas = np.genfromtxt(filename, delimiter=',', dtype=str)
for data in datas:
    sql = "	insert into vr_apk_download_log values (" + get_id() + ",'" + data[0] + "','" + data[
        1].replace('\t', '').replace('\"', '') + "','" + datetime.datetime.now().strftime(
        "%Y-%m-%d %H:%M:%S") + "','','" + data[2] + "')"
    cursor.execute(sql)

conn.commit()
# 关闭游标和连接
cursor.close()
conn.close()
